package com.example.springboot.controller;
import com.example.springboot.utils.ThreadLocalUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import com.example.springboot.service.CartService;
import com.example.springboot.pojo.Cart;
import com.example.springboot.pojo.Result;
@RestController
@CrossOrigin
@RequestMapping("/cart")
public class CartController {
    @Autowired
    private CartService cartService;
    @PostMapping("/create")
    public Result create(@RequestBody Cart cart){
        cartService.create(cart);
        return Result.success();
    }
    @DeleteMapping("/delete")
    public Result delete(Integer id){
        cartService.delete(id);
        return Result.success();
    }
    @GetMapping("/findByUserId")
    public Result findByUserId(){
        List<Cart> list=cartService.findByUserId();
        return Result.success(list);
    }
    @PutMapping("/update")
    public Result updateById(@RequestBody Cart cart) {
        cartService.updateById(cart);
        return Result.success();
    }
       @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        cartService.deleteBatch(ids);
        return Result.success();
    }

        @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Cart> page = cartService.selectPage(pageNum, pageSize);
        return Result.success(page);
    }
}
